<span page-title ng-model="repository">{{ 'Repository:' | translate }} {{ repository.name }}</span>

<div ng-hide="page.error" data-extend-template="layouts/two-column-details.html">
  <div data-block="left-column">
    <h4 translate>Basic Information</h4>

    <dl class="dl-horizontal dl-horizontal-left">
      <dt translate>Name</dt>
      <dd bst-edit-text="repository.name"
          on-save="save(repository)"
          readonly="product.redhat || denied('edit_products', product)">
      </dd>

      <dt translate>Label</dt>
      <dd>{{ repository.label }}</dd>

      <dt translate>Description</dt>
      <dd bst-edit-textarea="repository.description"
	  on-save="save(repository)"
	  readonly="product.redhat || denied('edit_products', product)">
      </dd>

      <dt translate>Backend Identifier</dt>
      <dd>{{ repository.backend_identifier }}</dd>

      <dt translate>Type</dt>
      <dd>{{ repository.content_type }}</dd>
    </dl>

    <div class="divider"></div>
    <h4 translate>Sync Settings</h4>
    <dl class="dl-horizontal dl-horizontal-left">
      <span ng-show="repository.content_type === 'yum'" >
        <dt>
          <span translate>Restrict to architecture</span>
          <i class="pficon-info" title="{{ 'The repository will be enabled by default on content hosts with the selected architecture.' | translate }}"></i>
        </dt>
        <dd bst-edit-select="repository.arch==='noarch'?'No restriction':repository.arch"
            selector="repository.arch"
            options="architectures()"
            on-save="save(repository)">
        </dd>
      </span>

      <span ng-show="repository.content_type === 'yum'" >
        <dt>
          <span translate>Restrict to <br />OS version</span>
          <i class="pficon-info" title="{{ 'The repository will be enabled by default on content hosts with the selected OS version.' | translate }}"></i>
        </dt>
        <dd bst-edit-select="repository.os_versions.length ? formatOSVersions() : 'No restriction'"
            selector="selectedOSVersion"
            options="osVersionsOptions()"
            on-save="save(repository)">
        </dd>
      </span>

      <dt ng-show="repository.content_type !== 'docker'" translate>Upstream URL</dt>
      <dt ng-show="repository.content_type === 'docker'" translate>Registry URL</dt>
      <dd bst-edit-text="repository.url"
          on-save="save(repository)"
          readonly="product.redhat || denied('edit_products', product)">
      </dd>
      <span ng-if="repository.content_type == 'deb'">
        <dt translate>Releases</dt>
        <dd bst-edit-text="repository.deb_releases"
            on-save="save(repository)"
            readonly="denied('edit_products', product)">
        </dd>
      </span>
      <span ng-if="repository.content_type == 'deb'">
        <dt translate>Components</dt>
        <dd bst-edit-text="repository.deb_components"
            on-save="save(repository)"
            readonly="denied('edit_products', product)">
        </dd>
      </span>
      <span ng-if="repository.content_type == 'deb'">
        <dt translate>Architectures</dt>
        <dd bst-edit-text="repository.deb_architectures"
            on-save="save(repository)"
            readonly="denied('edit_products', product)">
        </dd>
      </span>

      <span ng-show="repository.content_type === 'docker'" >
        <dt translate>Upstream Repository Name</dt>
        <dd bst-edit-text="repository.docker_upstream_name"
            on-save="save(repository)"
            readonly="product.redhat || denied('edit_products', product)">
        </dd>
      </span>

      <span ng-if="repository.content_type == 'ansible_collection'">
      <dt translate>Upload Requirements</dt>
        <dd>
          <input id="requirementFile" type="file" name="file_path" onclick="this.value = null" onchange="angular.element(this).scope().handleFiles(this)"/>
          <p bst-alert='info' ng-show="repository.content_type == 'ansible_collection'">
          <span translate>
            You can upload a requirements.yml file above to auto-fill contents <b>OR</b> paste contents of <a ng-href="https://docs.ansible.com/ansible/devel/dev_guide/collections_tech_preview.html#install-multiple-collections-with-a-requirements-file" target="_blank"> Requirements.yml </a>below.
          </span>
      </p>
        </dd>
      </span>

      <span ng-if="repository.content_type == 'ansible_collection'">
        <dt translate>Requirements</dt>
        <dd class="overflow-span" bst-edit-textarea="repository.ansible_collection_requirements"
            on-save="save(repository)"
            readonly="denied('edit_products', product)"
            edit-trigger="uploadedFile">
        </dd>
      </span>

      <dt ng-show="repository.content_type == 'ansible_collection'" translate>Auth URL</dt>
      <dd bst-edit-text="repository.ansible_collection_auth_url"
          on-save="save(repository)"
          readonly="product.redhat || denied('edit_products', product)">
      </dd>

      <dt ng-show="repository.content_type == 'ansible_collection'" translate>Auth Token</dt>
      <dd bst-edit-text="repository.ansible_collection_auth_token"
          on-save="save(repository)"
          readonly="product.redhat || denied('edit_products', product)">
      </dd>

      <dt translate>Verify SSL</dt>
      <dd bst-edit-checkbox="repository.verify_ssl_on_sync"
          formatter="booleanToYesNo"
          on-save="save(repository)"
          readonly="denied('edit_products', product)">
      </dd>

      <span ng-if="!product.redhat">
        <dt translate>Upstream Authorization</dt>
        <dd bst-edit-custom="repository.upstream_auth_exists"
            readonly="denied('edit_products', product)"
            on-save="save(repository, true)"
            formatter="upstreamPasswordFilter"
            formatter-options="repository"
            deletable="repository.upstream_auth_exists"
            on-delete="clearUpstreamAuth()">
          <div translate>Upstream Username</div>
          <input id="upstream_username"
                 name="upstream_username"
                 type="name"
                 autocomplete="off"
                 ng-model="repository.upstream_username"/>
          <div translate>Upstream Password</div>
          <input id="upstream_password"
                 name="upstream_password"
                 type="password"
                 autocomplete="off"
                 ng-model="repository.upstream_password"/>
        </dd>
      </span>

      <span ng-show="repository.content_type === 'yum'">
        <dt translate>Yum Metadata Checksum</dt>
        <dd bst-edit-select="checksumTypeDisplay(repository.checksum_type)"
            readonly="product.redhat || denied('edit_products', product)"
            selector="repository.checksum_type"
            options="checksums"
            on-save="save(repository)">
        </dd>
      </span>
      <span ng-hide="repository.content_type === 'ostree'">
        <dt translate>Mirror on Sync</dt>
        <dd bst-edit-checkbox="repository.mirror_on_sync"
            formatter="booleanToYesNo"
            on-save="save(repository)"
            readonly="denied('edit_products', product)">
        </dd>
      </span>

      <span>
        <dt translate>HTTP Proxy</dt>
        <dd bst-edit-custom="repository.http_proxy_policy"
            readonly="denied('edit_products', product)"
            on-save="save(repository)"
            formatter="httpProxyDetailsFilter"
            formatter-options="repository"
            >
          <div translate>HttpProxyPolicy</div>
          <form role="form">
            <div class="form-group">
              <select class="form-control"
                ng-options="type.label as type.name for type in policies"
                ng-model="repository.http_proxy_policy">
              </select>
            </div>
          </form>

          <span ng-show="repository.http_proxy_policy === 'use_selected_http_proxy'">
            <div translate>HTTP Proxy</div>
            <span translate ng-show="proxies.length == 0">
              No HTTP Proxies found
            </span>
            <span ng-show="proxies.length > 0">
              <form role="form">
                <div class="form-group">
                  <select class="form-control"
                    ng-model="repository.http_proxy_id"
                    ng-options="proxy.id as proxy.name for proxy in proxies"
                    ng-show="proxies.length > 0">
                  </select>
                </div>
              </form>
            </span>
          </span>
        </dd>
      </span>

      <span ng-if="repository.content_type === 'yum'">
        <dt translate>Ignorable Content</dt>
        <dd bst-edit-custom="repository.ignorable_content"
            readonly="denied('edit_products', product)"
            on-save="save(repository)"
            formatter="yumIgnorableContentFilter"
            formatter-options="repository"
            >
            <div translate>Use Ctrl-click to multi-select/deselect items.</div>
            <select id="ignorable_content"
                    name="ignorable_content"
                    multiple="true"
                    ng-model="repository.ignorable_content"
                    ng-options="id as name for (id, name) in ignorableYumContentUnits">
            </select>
        </dd>
      </span>

      <dt translate>Publish via HTTPS</dt>
      <dd translate>Yes</dd>

      <span ng-hide="repository.content_type === 'ostree' || repository.content_type === 'docker'">
        <dt translate>Publish via HTTP</dt>
        <dd bst-edit-checkbox="repository.unprotected"
            formatter="booleanToYesNo"
            on-save="save(repository)"
            readonly="product.redhat || denied('edit_products', product)">
        </dd>
      </span>

      <dt translate>Published At</dt>
      <dd>
        <a ng-hide="repository.content_type === 'docker'" ng-href="{{ repository.full_path }}">{{ repository.full_path }}</a>
        <span ng-show="repository.content_type === 'docker'">{{ repository.full_path }}</span>
        <p bst-alert='info' ng-hide="repository.unprotected">
          <span translate>
            In order to browse this repository you must <a ng-href="/organizations/{{ organization }}/edit">download the certificate</a>
            or ask your admin for a certificate.
          </span>
        </p>
      </dd>
      <span ng-if="repository.content_type == 'ostree'">
        <dt translate>Upstream Sync Policy</dt>
        <dd bst-edit-custom="repository.ostree_upstream_sync_policy"
            readonly="denied('edit_products', product)"
            on-save="save(repository)"
            formatter="ostreeUpstreamSyncPolicyFilter"
            formatter-options="repository"
            >
            <select ng-options="id as name for (id, name) in ostreeUpstreamSyncPolicies" ng-model="repository.ostree_upstream_sync_policy">
            </select>
            <input id="ostree_upstream_sync_depth"
              name="ostree_upstream_sync_depth"
              ng-model="repository.ostree_upstream_sync_depth"
              type="number"
              ng-disabled="repository.ostree_upstream_sync_policy !== 'custom'"/>
        </dd>
      </span>

      <span ng-if="(repository.content_type === 'yum' && !product.redhat) || repository.content_type === 'deb'">
        <dt translate>GPG Key</dt>
        <dd bst-edit-select="repository.gpg_key.name"
            readonly="product.redhat ||denied('edit_products', product)"
            selector="repository.gpg_key_id"
            options="gpgKeys()"
            on-save="save(repository)">
        </dd>
      </span>
      <dt translate>SSL CA Cert</dt>
      <dd bst-edit-select="repository.ssl_ca_cert.name"
          readonly="product.redhat ||denied('edit_products', product)"
          selector="repository.ssl_ca_cert_id"
          options="certs()"
          on-save="save(repository)">
      </dd>
      <dt translate>SSL Client Cert</dt>
      <dd bst-edit-select="repository.ssl_client_cert.name"
          readonly="product.redhat ||denied('edit_products', product)"
          selector="repository.ssl_client_cert_id"
          options="certs()"
          on-save="save(repository)">
      </dd>
      <dt translate>SSL Client Key</dt>
      <dd bst-edit-select="repository.ssl_client_key.name"
          readonly="product.redhat ||denied('edit_products', product)"
          selector="repository.ssl_client_key_id"
          options="certs()"
          on-save="save(repository)">
      </dd>
      <span ng-if="repository.content_type == 'yum'">
        <dt translate>Download Policy</dt>
        <dd bst-edit-select="downloadPolicyDisplay(repository.download_policy)"
            readonly="denied('edit_products', product)"
            selector="repository.download_policy"
            options="downloadPolicies"
            options-format="id as name for (id, name) in options"
            on-save="save(repository)">
        </dd>
      </span>
      <span ng-if="repository.content_type == 'docker'">
        <dt translate>Limit Sync Tags</dt>
        <dd bst-edit-text="repository.commaTagsWhitelist"
            on-save="save(repository)"
            readonly="denied('edit_products', product)">
        </dd>
      </span>
    </dl>

    <div class="divider"></div>

    <h4 translate>Sync Status</h4>

    <dl class="dl-horizontal dl-horizontal-left">
      <span ng-include="'products/details/partials/sync-status.html'"></span>

      <dt translate>Last Sync</dt>
      <dd ng-show="repository.last_sync == null" translate>
        Not Synced
      </dd>
      <dd ng-hide="repository.last_sync == null || repository.last_sync.ended_at == null">
        <relative-date date="repository.last_sync.ended_at" />
        (<short-date-time date="repository.last_sync.ended_at" /> <translate>Local Time</translate>)
      </dd>

      <dt translate>Next Sync</dt>
      <dd ng-show="repository.product.sync_plan.next_sync">
        <long-date-time date="repository.product.sync_plan.next_sync" /> (<translate>Server Time</translate>)
      </dd>
      <dd ng-hide="repository.product.sync_plan.next_sync" translate>
        Synced manually, no interval set.
      </dd>

      <dt translate>Sync State</dt>
        <dd>
          <a ng-show="repository.last_sync.result"
             ui-sref="product.repository.tasks.details({repositoryId: repository.id, taskId: repository.last_sync.id})">
            {{ repository.last_sync.result }}
          </a>
          <span ng-hide="repository.last_sync.result" translate>No sync information available.</span>
        </dd>
    </dl>
  </div>

  <div data-block="right-column">
    <section>
      <h4 translate>Content Counts</h4>

      <table class="table table-striped table-bordered">
        <thead>
        <tr>
          <th colspan="2" translate>Content Type</th>
        </tr>
        </thead>

        <tbody>
        <tr ng-show="repository.content_type === 'yum'">
          <td translate>Packages</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.packages({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.rpm || 0 }}
            </a>
          </td>
        </tr>

        <tr ng-show="repository.content_type === 'yum'">
          <td translate>Source RPMs</td>
          <td class="align-center">
            {{ repository.content_counts.srpm || 0 }}
          </td>
        </tr>

        <tr ng-show="repository.content_type === 'yum'">
          <td translate>Errata</td>
          <td class="align-center">
            <a ui-sref="errata({repositoryId: repository.id})">
              {{ repository.content_counts.erratum || 0 }}
            </a>
          </td>
        </tr>
        <tr ng-show="repository.content_type === 'yum'">
          <td translate>Package Groups</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.package-groups({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.package_group || 0 }}
            </a>
          </td>
        </tr>
        <tr ng-show="repository.content_type === 'yum'">
          <td translate>Module Streams</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.module-streams({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.module_stream || 0 }}
            </a>
          </td>
        </tr>
        <tr ng-show="repository.content_type === 'docker'">
          <td translate>Container Image Manifests</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.docker-manifests({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.docker_manifest || 0 }}
            </a>
          </td>
        </tr>
        <tr ng-show="repository.content_type === 'docker'">
          <td translate>Container Image Manifest Lists</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.docker-manifest-lists({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.docker_manifest_list || 0 }}
            </a>
          </td>
        </tr>

        <tr ng-show="repository.content_type === 'docker'">
          <td translate>Container Image Tags</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.docker-tags({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.docker_tag || 0 }}
            </a>
          </td>
        </tr>
        <tr ng-show="repository.content_type === 'ostree'">
          <td translate>OSTree Branches</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.ostree-branches({productId: product.id, repositoryId: repository.id})">
               {{ repository.content_counts.ostree_branch || 0 }}
            </a>
          </td>
        </tr>
        <tr ng-show="repository.content_type === 'file'">
          <td translate>Files</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.files({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.file || 0 }}
            </a>
          </td>
        </tr>
        <tr ng-show="repository.content_type === 'deb'">
          <td translate>deb Packages</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.debs({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.deb || 0 }}
            </a>
          </td>
        </tr>
        <tr ng-show="repository.content_type === 'ansible_collection'">
          <td translate>Ansible Collections</td>
          <td class="align-center">
            <a ui-sref="product.repository.manage-content.ansible-collections({productId: product.id, repositoryId: repository.id})">
              {{ repository.content_counts.ansible_collection || 0 }}
            </a>
          </td>
        </tr>
        </tbody>
      </table>

      <div class="divider" ng-if="repository.content_type === 'ostree'"/>
    </section>

    <section class="well" ng-if="permitted('edit_products', product) && !product.redhat && repository.content_type !== 'docker' && repository.content_type !== 'ostree'">
      <h5 translate ng-show="repository.content_type === 'yum'">Upload Package</h5>
      <h5 translate ng-show="repository.content_type === 'file'">Upload File</h5>

      <form role="form"
            action="{{ uploadURL }}"
            ng-upload="uploadContent(content)"
            error-catcher="uploadError(error, content)"
            upload-options-enable-controls
            upload-options-enable-rails-csrf>

        <div class="form-group">
          <input type="file" name="content[]" ng-hide="denied('edit_products', product)" multiple/>
        </div>

        <div class="form-group">
          <button type="button" class="btn btn-primary"
                  ng-hide="denied('edit_products', product)"
                  upload-submit ng-click="progress.uploading = true">
            <i class="fa fa-spinner fa-spin" ng-show="progress.uploading"></i>
            <span ng-show="progress.uploading" translate>Uploading...</span>
            <span ng-hide="progress.uploading" translate>Upload</span>
          </button>
        </div>

      </form>
    </section>

    <section ng-show="repository.content_type === 'yum'">
      <div class="divider"></div>
      <h4 translate>Distribution Information</h4>

      <div class="detail" >
        <span class="info-value" ng-hide="repository.distribution_version ||
           repository.distribution_arch ||
           repository.distribution_family ||
           repository.distribution_variant">No distribution available</span>

        <section ng-show="repository.distribution_version ||
           repository.distribution_arch ||
           repository.distribution_family ||
           repository.distribution_variant">

          <div class="detail">
            <dt translate>Version</dt>
            <dd>{{ repository.distribution_version }}</dd>
          </div>

          <div class="detail">
            <dt translate>Architecture</dt>
            <dd>{{ repository.distribution_arch}}</dd>
          </div>

          <div class="detail">
            <dt translate>Family</dt>
            <dd>{{ repository.distribution_family}}</dd>
          </div>

          <div class="detail">
            <dt translate>Variant</dt>
            <dd>{{ repository.distribution_variant}}</dd>
          </div>

          <div class="detail">
            <dt translate>Bootable</dt>
            <dd>{{ repository.distribution_bootable}}</dd>
          </div>
        </section>
      </div>
    </section>
  </div>
</div>
